#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
获取微信订阅号永久素材列表 - 简单使用示例
"""

from wechat_material import WeChatMaterial
import json

def main():
    """主函数 - 获取永久素材列表"""
    
    # 创建微信素材管理实例
    wechat = WeChatMaterial()
    
    print("=== 获取微信订阅号永久素材列表 ===")
    
    # 获取素材总数统计
    print("正在获取素材统计信息...")
    count_info = wechat.get_material_count()
    if count_info:
        print("素材统计:")
        for key, value in count_info.items():
            print(f"  {key}: {value}")
    
    # 获取图片素材列表
    print("\n正在获取图片素材...")
    images = wechat.get_material_list("image", 0, 20)
    if images and 'item' in images:
        print(f"获取到 {len(images['item'])} 个图片素材")
        for i, img in enumerate(images['item'][:5], 1):  # 只显示前5个
            print(f"  {i}. {img.get('name', 'N/A')}")
    
    # 获取图文素材列表
    print("\n正在获取图文素材...")
    news = wechat.get_material_list("news", 0, 10)
    if news and 'item' in news:
        print(f"获取到 {len(news['item'])} 个图文素材")
        for i, item in enumerate(news['item'][:3], 1):  # 只显示前3个
            news_item = item.get('content', {}).get('news_item', [])
            if news_item:
                print(f"  {i}. {news_item[0].get('title', 'N/A')}")
    
    # 获取语音素材列表
    print("\n正在获取语音素材...")
    voices = wechat.get_material_list("voice", 0, 10)
    if voices and 'item' in voices:
        print(f"获取到 {len(voices['item'])} 个语音素材")
    
    # 获取视频素材列表
    print("\n正在获取视频素材...")
    videos = wechat.get_material_list("video", 0, 10)
    if videos and 'item' in videos:
        print(f"获取到 {len(videos['item'])} 个视频素材")
    
    print("\n=== 获取完成 ===")

if __name__ == "__main__":
    main()
